package com.appleyk.controller;

import com.appleyk.entity.A;
import com.appleyk.result.ResponseMessage;
import com.appleyk.result.ResponseResult;
import com.appleyk.service.ObjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ObjectController {

    @Autowired
    private ObjectService objService;

    @GetMapping("/rest/object/save")
    public ResponseResult SaveObject(@RequestParam("name") String name, @RequestParam("sex") String sex, @RequestParam("age") Integer age) throws Exception {

        A a = new A();
        a.setAge(age);
        a.setSex(sex);
        a.setName(name);
        if (objService.Save(a)) {
            return new ResponseResult(ResponseMessage.OK);
        }
        return new ResponseResult(ResponseMessage.INTERNAL_SERVER_ERROR);
    }
}
